/**
 * @author roua_troua
 */

package q10.GUI;

import q10.ArboriFunctionali;
import javax.swing.JTextField;
import q10.Visitor.*;

public class CalculField implements Command{
    private ArboriFunctionali a;
    private JTextField textCalcul;
    private ArboriFunctionali stareA;
    private String stareText;

    public CalculField(ArboriFunctionali a,JTextField tc){
        this.a = a;
        this.textCalcul = tc;
    }

    public ArboriFunctionali execute(){
        getStare();
        Visitor calculVisitor = new CalculVisitor();
        a.acceptVisitor(calculVisitor);
        textCalcul.setText(Double.toString(((CalculVisitor)calculVisitor).getCalcul()));
        return a;
    }

    public ArboriFunctionali unexecute(){
        this.a = stareA;
        textCalcul.setText(stareText);
        return a;
    }

    public void getStare(){
        this.stareA = a;
        this.stareText = textCalcul.getText();
    }

    public void update(ArboriFunctionali af){
        this.a = af;
    }

}
